<?php
class Admin_Form_Role extends TBB_Form
{
	public function init()
	{
		$this->addAttribs(array(
			'class' => 'span-8',
			//'style' => 'background-color: #ccc;'
		));
		
		// create id element
		$id = $this->_createRoleIDElement();
		
		// create role name element
		$roleName = $this->_createRoleNameElement();
		
		// create description element 
		$description = $this->_createDescriptionElement();
		
		// create submit button
		$submit = $this->_createSubmitElement();
		
		// add all elements
		$this->addElements(array($id, $roleName, $description, $submit));
		$this->addDisplayGroup(array('role_id', 'role_name', 'description', 'submit'), 'roleGroup');		
		
		// set decorators for form
		$this->setDecorators($this->_formDecorators);
		$this->setDisplayGroupDecorators($this->_displayGroupDecorators);	
	}
	
	private function _createSubmitElement()
	{
		$submit = $this->createElement('submit', 'submit');
		$submit->setLabel('Chấp nhận');		
		$submit->setDecorators($this->_submitDecorators);
		$submit->getDecorator('HtmlTag')->setOption('id', 'createRoleButton');
		$submit->setAttribs(array(
			'class' => 'span-4 last submitDecorator',
		));
		return $submit;
	}
	
	private function _createDescriptionElement()
	{
		$description = $this->createElement('text', 'description')
							->setLabel('Mô tả chức vụ: ')
							->setRequired(true)
							->addFilter('StripTags')
							->addErrorMessage('Làm ơn nhập mô tả chức vụ.');
		$description->setAttribs(array(
			'class' => 'column span-6 last',
		));
		$description->getDecorator('Label')->setOption('class', 'column span-4 labelDecorator');
		$description->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		return $description;
	}
	
	private function _createRoleNameElement()
	{
		$roleName = $this->createElement('text', 'role_name')
						 ->setLabel('Tên chức vụ: ')
						 ->setRequired(true)
						 ->addFilter('StripTags')
						 ->addErrorMessage('Làm ơn nhập tên chức vụ.');
		$roleName->setAttribs(array(
			'class' => 'column span-6 last',
		));
		$roleName->getDecorator('Label')->setOption('class', 'column span-4 labelDecorator');
		$roleName->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		return $roleName;		
	}
	
	private function _createRoleIDElement()
	{
		$id = $this->createElement('hidden', 'role_id');
		$id->setDecorators($this->_hiddenDecorators);
		$id->setAttribs(array(
			'class' => 'span-4',
		));
		return $id;		
	}
}